package com.zhp.ggweather.util;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo.State;

public class NetUtil {
	public static final int NETWORK_NONE=0;
	public static final int NETWORK_WIFI=1;
	public static final int NETWORK_MOBILE=2;
	public static int getNetworkState(Context context){
		ConnectivityManager connectManager=(ConnectivityManager)context
				.getSystemService(Context.CONNECTIVITY_SERVICE);
		//wifi
		State state=connectManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();
		if(state==State.CONNECTED || state==State.CONNECTING){
			return NETWORK_WIFI;
		}
		//3g
		state=connectManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState();
		if(state==State.CONNECTED || state==State.CONNECTING){
			return NETWORK_MOBILE;
		}
		return NETWORK_NONE;
	}
}
